package org.example.thread;

import lombok.SneakyThrows;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

public class FutureDemo01 {
    @SneakyThrows
    public static void main(String[] args) {
        //创建线程池
        ExecutorService executorService = new ThreadPoolExecutor(8,16,30000, TimeUnit.MICROSECONDS
        , new LinkedBlockingQueue<>(1000));
        //线程执行,有返回值的
        Future<Integer> future = executorService.submit(() -> {
            TimeUnit.SECONDS.sleep(4);
            System.out.println(Thread.currentThread().getName()+"执行！传递结果中");
            return 12;
        });

        System.out.println(Thread.currentThread().getName()+":"+future.get());
        executorService.shutdown();

    }
}
